/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint.core.mapping;

import info.xmlprint.core.format.Format;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/*
 * Klass fuer ein Tags-Format Zuordnung * 
 * 
 */
public class Mapping implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5791651323807084790L;

	private String xPath;
	private String name;
	private Format format;

	private boolean isActive = true;

	// xpathText: 0
	// per mouse: 1
	private String select = "0";

	private Set<ElementPath> elementPathSet = new HashSet<ElementPath>();

	public void setFormat(Format f) {
		format = f;
	}

	public Format getFormat() {
		return format;
	}

	public String getSelect() {
		return select;
	}

	public void setSelect(String select) {
		this.select = select;
	}

	public Set<ElementPath> getElementPathSet() {
		return elementPathSet;
	}

	public boolean getActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	/*
	 * public void setElementPathSet(Set<ElementPath> elementPathSet) {
	 * this.elementPathSet = elementPathSet; }
	 */

	public String getFormatName() {
		if (format == null || format.getName() == null)
			return "";

		return format.getName();
	}

	public boolean contains(ElementPath ep) {
		return elementPathSet.contains(ep);
	}

	public String getxPath() {
		return xPath;
	}

	public void setxPath(String xPath) {
		this.xPath = xPath;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Mapping() {

	}

	public void addElementPath(ElementPath ef) {
		elementPathSet.add(ef);
	}

	public void removeElemntFormat(ElementPath ef) {
		elementPathSet.remove(ef);
	}

	public void removeAll() {
		elementPathSet = new HashSet<ElementPath>();
	}

	public ElementPath[] getElementPaths() {
		return elementPathSet.toArray(new ElementPath[0]);
	}

	public void printAll() {
		System.out.println(name);
		for (String key : format.getAttributeNames()) {
			System.out.println(key + ": " + format.getAttribute(key));
		}
		for (String key : format.getFootnoteAttributNames()) {
			System.out.println(key + ": " + format.getFootnoteAttribute(key));
		}
		System.out.println("*************");
	}

}
